package logic

import (
	"context"
	"group/model/redis"
	"group/pkg"
	"time"

	"group/grouprpc/grouprpc"
	"group/grouprpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SendSmsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLogic {
	return &SendSmsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SendSmsLogic) SendSms(in *grouprpc.SendSmsRequest) (*grouprpc.SendSmsResponse, error) {
	// todo: add your logic here and delete this line
	redis.Rdb.Get("sendSms" + in.Source + in.Account)

	sms, err := pkg.SendSms(in.Account, in.Source)
	if err != nil {
		return nil, err
	}
	redis.Rdb.Set("sendSms"+in.Source+in.Account, sms, time.Minute*5)

	redis.Rdb.Set("sendHour"+in.Source+in.Account, 5, time.Hour*1)

	return &grouprpc.SendSmsResponse{}, nil
}
